package nowCoder;

/**
 * Created by Ghost on 2015/1/28 0028.
 */
public class CanReachTop {
    private boolean canReach(int i,boolean[][] w){
        if(i==0)
            return true;
        boolean rst = false;
        for(int j=0;j<i;j++){
            rst = rst || w[j][i];
        }
        return rst;
    }

    public boolean jump(int array[], int size) {
        int n = array.length;
        boolean[][] w = new boolean[n][n];
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                if(canReach(i,w)){
                    if(j-i<=array[i]){
                        w[i][j]=true;
                        if(j==n-1)
                            return true;
                    }
                }
            }
        }
        return false;
    }

    public static void main(String[] args){
        CanReachTop canReachTop = new CanReachTop();
        int[] a = {4,2,2,1,0,2};
        System.out.println(canReachTop.jump(a,3));
    }
}
